package aksk

import (
	"crypto/sha256"
	"encoding/hex"
	uuid "github.com/satori/go.uuid"
	"strconv"
	"strings"
	"time"
)

// GenAppKey 生成appKey
func GenAppKey() string {
	appKey := uuid.NewV4().String()
	return strings.Replace(appKey, "-", "", -1)
}

// GenAppSecret 生成appSecret
// sha256(appKey + name + timestamp)
func GenAppSecret(appKey, name string) string {
	nano := time.Now().UnixNano()
	data := appKey + name + strconv.FormatInt(nano, 10)
	appSecretArray := sha256.Sum256([]byte(data))
	appSecretSlice := appSecretArray[:]
	return hex.EncodeToString(appSecretSlice)
}
